package com.spring.springboot.tree;

import com.alibaba.fastjson.JSON;

import java.util.ArrayList;
import java.util.List;

/**
 * 项目名称: java_algorithm
 * @ClassName JsonTree
 * @Description
 * @Author huipanxing huipanxing@chinasofti.com   @Date 2022/6/17 11:17
 */
public class JsonTree {

    public static void main(String[] args) {
        int i = 1;
        List<Tree> list=new ArrayList<>();
        for (int n = 1; n <= 100; n++) {
            Tree tree1 = new Tree();
            final Tree tree2 = new Tree();
            tree1.setId(i++);
            tree1.setLabel(tree1.getId().toString());

            if (i%3==1){
//                tree2 = new Tree();
                tree2.setId(i++);
                tree2.setLabel(tree1.getId()+"-"+tree2.getId());

                tree1.setChildren(new ArrayList<Tree>() {{
                    add(tree2);
                }});
            }

            if (i%3==2){
                Tree tree3 = new Tree();
                tree3.setId(i++);
                tree3.setLabel(tree1.getId()+"-"+tree2.getId()+"-"+tree3.getId());

                tree2.setChildren(new ArrayList<Tree>() {{
                    add(tree3);
                }});
            }

            list.add(tree1);
        }
        System.out.println(JSON.toJSONString(list));
    }
}
